/*
 * @Author: szx
 * @Date: 2022-05-05 14:23:46
 * @LastEditTime: 2022-05-05 14:35:12
 * @Description:
 * @FilePath: \leetcode\700-799\797\797_2.js
 */
var allPathsSourceTarget = function (graph) {
    const n = graph.length - 1,
        stack = [0],
        res = [];
    const dfs = (i) => {
        if (i == n) {
            res.push(Array.from(stack));
            return;
        }
        for (let j of graph[i]) {
            stack.push(j);
            dfs(j);
            stack.pop();
        }
    };
    dfs(0);
    return res;
};
